package com.ruoyi.web.ydz.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.ydz.domain.MedicationReminder;
import com.ruoyi.web.ydz.service.IMedicationReminderService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

import java.util.List;

/**
 * 用药提醒功能Controller
 * 
 * @author DRX
 * @date 2024-10-15
 */
@RestController
@RequestMapping("/api/reminder")
public class MedicationReminderController extends BaseController
{
    @Resource
    private IMedicationReminderService medicationReminderService;

    /**
     * 查询用药提醒功能列表
     */
    @PreAuthorize("@ss.hasPermi('api:reminder:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody MedicationReminder medicationReminder)
    {
        startPage();
        List<MedicationReminder> list = medicationReminderService.selectMedicationReminderList(medicationReminder);
        return getDataTable(list);
    }

    /**
     * 导出用药提醒功能列表
     */
    @PreAuthorize("@ss.hasPermi('api:reminder:export')")
    @Log(title = "用药提醒功能", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MedicationReminder medicationReminder)
    {
        List<MedicationReminder> list = medicationReminderService.selectMedicationReminderList(medicationReminder);
        ExcelUtil<MedicationReminder> util = new ExcelUtil<MedicationReminder>(MedicationReminder.class);
        util.exportExcel(response, list, "用药提醒功能数据");
    }

    /**
     * 获取用药提醒功能详细信息
     */
//    @PreAuthorize("@ss.hasPermi('api:reminder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(medicationReminderService.selectMedicationReminderById(id));
    }

    /**
     * 新增用药提醒功能
     */
    @PreAuthorize("@ss.hasPermi('api:reminder:add')")
    @Log(title = "用药提醒功能", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody MedicationReminder medicationReminder)
    {
        return toAjax(medicationReminderService.insertMedicationReminder(medicationReminder));
    }

    /**
     * 修改用药提醒功能
     */
//    @PreAuthorize("@ss.hasPermi('api:reminder:edit')")
    @Log(title = "用药提醒功能", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody MedicationReminder medicationReminder)
    {
        return medicationReminderService.updateMedicationReminder(medicationReminder);
    }

    /**
     * 删除用药提醒功能
     */
    @PreAuthorize("@ss.hasPermi('api:reminder:remove')")
    @Log(title = "用药提醒功能", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(medicationReminderService.deleteMedicationReminderByIds(ids));
    }
}
